module.exports = class extends think.Controller {
    async __before() {
        if (this.ctx.action === 'login' || this.ctx.controller == "hook") {
            return;
        }

        let self = this;
        let userToken = this.header("x-token");
        // think.logger.info(self.header('x-token'));
        if (think.isEmpty(userToken)) {
            return this.fail(9998, '验证失败，请重新登录');
        }

        let tokenServiceInstance = this.service('token');
        let verifyTokenResult = await tokenServiceInstance.verifyToken(userToken);
        //think.logger.info(verifyTokenResult);
        if (!verifyTokenResult) {
            think.logger.info("token不对")
            return this.fail(9997, '登录过期，请重新登录');
        } else {
            think.logger.info("验证成功");
            return;
        }
    }
};